/*!
 @file MujiMediaLoadRequestManager.h
 @framework ECCoreLibrary

 @author Created by Paul Cantrell on 6/11/14.
 @copyright Copyright (c) 2014 EnglishCentral, Inc. All rights reserved.
 
 @internal
*/


#import <Foundation/Foundation.h>
#import "MujiMediaLoadRequest.h"
#import "MujiApplicationStateManagementProtocol.h"

@class MujiMediaLoadRequest;

/*!
 @class MujiMediaLoadRequestManager
 @abstract Singleton to keep track of cached movies and in progress downloads.
 
 @discussion  The class creates a cache directory and in that directory it keeps a bom.pinfo file which
 is a serialized directory where each directory entry is a serialized MediaLoadRequest object.
 During startup, the manager reads the bom.pinfo file, removes any entries that don't have a
 corresponding movie file (say, if the download got interrupted), and also removes any movie
 files that don't correspond to a MediaLoadRequest (orphaned movies?).
 
 Generally requests are made for a target url. This url is the key to the request dictionary
 so it's generally a quick lookup to see if the url has previously been cached. The other way
 a lookup can occur is when the MyHTTPConnection object is trying to find a request beased on
 the encoded url. This url is based on the local filename which is a GUID (i.e. guarenteed to
 be unique globally). In this case we walk all the requests looking for one that has that
 name. While we could use a second directory to track requests based on GUID, for the smallish
 number of requests we expect to cache, it probably isn't worth the complexity (and this only
 happens once each time a movie is played so the overhead is negligable).
 */
@interface MujiMediaLoadRequestManager : NSObject
<
    MujiMediaLoadRequestDelegate,
    MujiApplicationStateManagementProtocol
>

@property (readonly, nonatomic, copy) NSString *moviesDirectoryPath;

+ (MujiMediaLoadRequestManager *)manager;
- (void)cancelDownloadsInProgress;
- (MujiMediaLoadRequest *)requestWithUrlString:(NSString *)urlString;
- (MujiMediaLoadRequest *)existingRequestWithLocalFilename:(NSString *)localFilename;
- (NSString *)localFileForUrlString:(NSString *)urlString;
- (void)setDate:(NSDate *)date forRequest:(MujiMediaLoadRequest *)request;
- (void)trimDataUsageTo:(UInt64)bytes;
- (UInt64)cachedSpaceInUse;


@end
